<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>面向字节编程-cookie</title>
</head>
<body>
<script>
// cookie 属于某个域名的 domain 拿不到juejin的cookie
// console.log(document.cookie, '----------------');
// cookie 的优点是 每次传输都可以带上, 他是一段文本， 
// 拿到某一个cookie name 的值
const cookieObj = {};
const cookieStr = '_ga=GA1.2.202382987.1605787358; ttcid=9f48283093684b4abb5d4907bd7fe80f17; passport_csrf_token_default=c1b33ec43273771c41849e7cabae2756; passport_csrf_token=c1b33ec43273771c41849e7cabae2756; MONITOR_WEB_ID=f5be05b4-4168-4ed6-9d82-9859df9dc30e; _gid=GA1.2.2102805136.1630581198; tt_scid=AoIyLxoDXUJ7cqWjlnJ3WmfuT.I4vV6rS7fApdFJ-p7358reFLZcIuBSzRc-xW0Jff69'
const parseCookie = str =>
  str
    .split(';')
    // 变形的
    .map(v => v.split("="))
    // 二位数组 编程一个{} 把数组推平的方法, 
    .reduce((acc, v) => { 
      acc[v[0]] = v[1]
      return acc
    }  , {})
console.log(parseCookie(cookieStr));
</script>
</body>
</html>
